
#include "UnitFactory.h"

UnitFactory* UnitFactory::defaultInstance = NULL;
UnitFactory::UnitFactory()
{

}

UnitFactory* UnitFactory::getInstance()
{
	if(NULL == defaultInstance)
	{
		defaultInstance = new UnitFactory();
	}
	return defaultInstance;
}

Unit* UnitFactory::getUnit(string type)
{
	map<string,Unit*>::const_iterator  iter;
	iter = unitMap.find(type);

	if(iter != unitMap.end())
		return iter->second;

	if("MILE" ==  type)
	{
		Unit* unit = new UnitImpl(1760*3);
		unitMap["MILE"] = unit;
		return unit;
	}

	if("YARD" ==  type)
	{
		Unit* unit = new UnitImpl(3);
		unitMap["YARD"] = unit;
		return unit;
	}

	if("FEET" ==  type)
	{
		Unit* unit = new UnitImpl(1);
		unitMap["FEET"] = unit;
		return unit;
	}

	if("OZ" ==  type)
	{
		Unit* unit = new UnitImpl(4*3);
		unitMap["OZ"] = unit;
		return unit;
	}

	if("TSP" ==  type)
	{
		Unit* unit = new UnitImpl(4);
		unitMap["TSP"] = unit;
		return unit;
	}

	if("TBSP" ==  type)
	{
		Unit* unit = new UnitImpl(1);
		unitMap["TBSP"] = unit;
		return unit;
	}
}

